﻿#pragma once
#include <map>
#include <memory>
#include <string>
#include <optional>

class FTexture2D;


class FRanderTarget
{
public:

	inline static std::string DepthTextureName = "Depth";
	inline static std::string StencilTextureName = "Stencil";


	FRanderTarget();

	~FRanderTarget();

	/**
	 * \brief 绑定一个纹理
	 * \param Texture 
	 * \param TextureName 
	 * \return bool 是否绑定成功 ， int32_t 绑定的Index 
	 */
	std::tuple<bool, int32_t> BindTextureAsColorAttach(const std::shared_ptr<FTexture2D>& Texture, const std::string& TextureName);

	bool BindRanderBufferAsDepthAttach(int32_t Width, int32_t Height) const;

	bool BindTextureAsDepthAttach(const std::shared_ptr<FTexture2D>& Texture, const std::string& TextureName = DepthTextureName);
	bool BindTextureAsDepthAttach(int32_t Width, int32_t Height, const std::string& TextureName = DepthTextureName);

	bool BindTextireAsStencilAttach(const std::shared_ptr<FTexture2D>& Texture, const std::string& TextureName = StencilTextureName);
	bool BindTextireAsStencilAttach(int32_t Width, int32_t Height, const std::string& TextureName = StencilTextureName);


	std::shared_ptr<FTexture2D> GetTexture(const std::string& TextureName);

	void Used() const;

private:

	std::map<std::string, std::shared_ptr<FTexture2D>> BindTextureMap;

	int32_t CurrentColorAttachIndex = 0;

	uint32_t FBO = 0;
};
